package cellGame.scene.unit
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class Cell extends Sprite
	{
		private var _targetPoint:Point;
		private var _speed:Number = 10;
		
		public function Cell()
		{
			_targetPoint = new Point();
			
			graphics.beginFill(0xff4444,0.5);
			graphics.drawEllipse(-20,-40,40,80);
			graphics.endFill();
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		public function move(targetX:Number, targetY:Number):void
		{
			_targetPoint.x = targetX;
			_targetPoint.y = targetY;
		}
		
		private function onEnterFrame(e:Event):void
		{
			var dx:Number = _targetPoint.x - this.x;
			var dy:Number = _targetPoint.y - this.y;
			
			if(Math.abs(dx) <= _speed) this.x = _targetPoint.x;
			else this.x += _speed * (Math.abs(dx)/dx);

			if(Math.abs(dy) <= _speed) this.y = _targetPoint.y;
			else this.y += _speed * (Math.abs(dy)/dy);
		}
		
		//
	}
}